package agile.tools;

import java.lang.reflect.Field;

import agile.tools.domain.Account;
import agile.tools.domain.Address;
import agile.tools.domain.Person;
import agile.tools.domain.PhoneNumber;
import agile.tools.web.SomeComplexController;

public class Driver {
	public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException {
		Account a1 = new Account(123, 100);
		Account a2 = new Account(456, 200);
		Address add1 = new Address("tuttles creek", "OH", "Dublin", "43016");
		Address add2 = new Address("sawmill village dr", "OH", "Columbus", "43235");
		PhoneNumber ph1 = new PhoneNumber("443", "3233323");
		PhoneNumber ph2 = new PhoneNumber("657", "9466354");
		
		Person p1 = new Person();
		p1.setName("QWERTY");
		p1.addAccount(a1);
		p1.addPhone(ph1);
		p1.addPhone(ph2);
		p1.addAddress("Home", add1);
		p1.addAddress("Office", add2);
		
		System.out.println(p1);
		
		SomeComplexController c = new SomeComplexController();
		Person p2 = c.someComplexMethod(p1, a2);
		c.add(4,5);
		c.save(p1);
		c.add(9, a1);
		c.getMessage();
		
		System.out.println(p2);
		
//		tryReflection(p1);
//		tryReflection(a1);
	}
	
	public static void tryReflection(Object obj) throws IllegalArgumentException, IllegalAccessException {
		Class clazz = obj.getClass();
		Field[] fields = clazz.getDeclaredFields();
		for(Field f: fields) {
			System.out.println(f.getType() + " : " + f.getName() + " : " + f.getType().isPrimitive() + " : " + f.getType().isMemberClass());
			f.setAccessible(true);
			Object o = f.get(obj);
			System.out.println("--->> " + o);
		}
		if(obj.getClass().getSuperclass() != null) {
			System.out.println(obj.getClass().getSuperclass());
		}
	}
	
//	public static void printObject(Object object) {
//		Field[] fields = object.getClass().getDeclaredFields();
//		for(Field f: fields) {
//			System.out.println(f.getType() + " : " + f.getName());
//			f.setAccessible(true);
//			Object o = f.get(object);
//			System.out.println("--->> " + o);
//		}
//	}
}